<?php

namespace app\home\controller;

use think\facade\Request;
// use Endroid\QrCode\QrCode;
use dh2y\qrcode\QRcode;

//composer require dh2y/think-qrcode=2.*
//教程网站
//https://www.cnblogs.com/makalochen/p/13278531.html

class Index 
{
    public function index()
    {

        try {
            $code = new QRcode();
            $register_url = '二维码的内嵌的网址';
            $filename = 'qrcode/'.time().rand(10000,9999999).'.png';
            $code =  $code->png($register_url,$filename)->getPath();      
            $image_data = chunk_split(base64_encode(fread(fopen($filename, 'r'), filesize($filename))));
             //生成二维码
            $strUrl = "data:image/png;base64,".$image_data;
            echo "<img src='".$strUrl."'/>";

            dump($strUrl);
            dump($image_data);exit;

        } catch (\Exception $e) {
            // var_dump($e);exit;
            trace($e->getMessage());
            return ['code' => 1300, 'msg' => config('exception_msg')];
        }
       
   
    }

 
    
}
